package cn.qhuan.modules.service.impl;

import cn.qhuan.modules.constos.PageResponseResult;
import cn.qhuan.modules.dtos.TagDto;
import cn.qhuan.modules.entity.Tag;
import cn.qhuan.modules.entity.Tag;
import cn.qhuan.modules.mapper.TagMapper;
import cn.qhuan.modules.mapper.TagMapper;
import cn.qhuan.modules.service.ITagService;
import cn.qhuan.modules.service.ITagService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.springframework.stereotype.Service;

/**
 * @Description: 标签表
 * @Author: 司翔宇
 * @Date:   2021-01-07
 * @Version: V1.0
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {

    @Override
    public Result<?> queryByKeyWord(TagDto dto) {
        //1.检查参数
        if ( dto == null){
            return Result.error("缺少参数");
        }
        //分页检查
        dto.checkParam();
        //关键字模糊查询
        IPage pageParam =new Page(dto.getPage(),dto.getSize());
        LambdaQueryWrapper<Tag> lambdaQueryWrapper =new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(dto.getKeyword())){
            lambdaQueryWrapper.like(Tag::getName,dto.getKeyword());
        }
        //封装结果进行返回
        IPage pageList = page(pageParam, lambdaQueryWrapper);

        PageResponseResult responseResult =new PageResponseResult(dto.getPage(),dto.getSize(), (int) pageList.getTotal());
        responseResult.setResult(pageList.getRecords());
        return responseResult;
    }
}
